/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.minhphuong.dal;

import com.minhphuong.entities.SanPham;
import com.minhphuong.entities.TinhTrangSanPham;
import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author MINHPHUONG
 */
public class TinhTrangSanPhamDAL {
    public static TinhTrangSanPham getTinhTrangSanPhamByID(int id) {
        TinhTrangSanPham ttsp = null;
        Session session = null;

        try {
            session = HelperDAL.GetSession();
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from TinhTrangSanPham where maTtsp=:id").setInteger("id", id);
            ttsp = (TinhTrangSanPham) q.list().get(0);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
           
            session.flush();
            session.close();
        }
        return ttsp;
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    public static List<TinhTrangSanPham> getAllTTSP() {
        List<TinhTrangSanPham> listTTSP = null;
        Session session = null;

        try {
            session = HelperDAL.GetSession();
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from TinhTrangSanPham");
            listTTSP = (List<TinhTrangSanPham>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            
            session.flush();
            session.close();
        }

        return listTTSP;
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
